﻿using BaseDal;
using Models;
using System;
using System.Collections.Generic;
using System.Data;

namespace BaseBll
{
    public class PostBll
    {
        static readonly Lazy<PostBll> bll = new Lazy<PostBll>(() => new PostBll());
        public static PostBll Instance { get; } = bll.Value;
        readonly PostDal DaoInstance;
        private PostBll() { DaoInstance = PostDal.Instance; }

        /// <summary>
        /// 查询数据是否存在
        /// </summary>
        /// <param name="strWhere"></param>
        /// <returns></returns>
        public bool IsExist(string strWhere)
        {
            return DaoInstance.IsExist(strWhere);
        }

        /// <summary>
        /// 查询分页数据
        /// </summary>
        /// <param name="pageSize"></param>
        /// <param name="pageIndex"></param>
        /// <param name="strWhere"></param>
        /// <param name="filedOrder"></param>
        /// <param name="recordCount"></param>
        /// <returns></returns>
        public DataTable GetPageList(int pageSize, int pageIndex, string strWhere, string filedOrder, out int recordCount)
        {
            return DaoInstance.GetPageList(pageSize, pageIndex, strWhere, filedOrder, out recordCount);
        }

        /// <summary>
        /// 查询数据
        /// </summary>
        /// <param name="strWhere"></param>
        /// <returns></returns>
        public List<Post> GetList(string strWhere)
        {
            return DaoInstance.GetList(strWhere);
        }

        /// <summary>
        /// 根据id查询实体类
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Post GetModelById(int id)
        {
            return DaoInstance.GetModelById(id);
        }

        /// <summary>
        /// 新增岗位
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int AddPost(Post model)
        {
            return DaoInstance.AddPost(model);
        }

        /// <summary>
        /// 修改岗位
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int UpdatePost(Post model)
        {
            return DaoInstance.UpdatePost(model);
        }

        /// <summary>
        /// 删除岗位
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public int DeletePost(List<string> id, string userName)
        {
            return DaoInstance.DeletePost(id, userName);
        }

        /// <summary>
        /// 修改状态（启用、禁用）
        /// </summary>
        /// <param name="id"></param>
        /// <param name="userName"></param>
        /// <returns></returns>
        public int UpdateStatus(int id, int status, string userName)
        {
            return DaoInstance.UpdateStatus(id, status, userName);
        }

        /// <summary>
        /// 验证model各字段合法性
        /// </summary>
        /// <param name="model"></param>
        /// <param name="msg">错误信息</param>
        /// <returns></returns>
        public bool VerifyModel(Post model, ref string msg)
        {

            if (string.IsNullOrEmpty(model.PostName))
            {
                msg = "岗位名称不能为空";
                return false;
            }

            return true;
        }

    }
}
